package com.xzh.gulimall.order.vo;

import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

//订单确认页需要的数据
public class OrderConfirmVo {
    //收获地址
    @Getter
    @Setter
    private List<MemberAdressVo> address;
    //所有选中的购物项
    @Getter
    @Setter
    private List<OrderItemVo> items;
    //发票记录...

    //优惠卷信息
    @Getter
    @Setter
    private Integer integration;

    @Getter
    @Setter
    Map<Long, Boolean> stocks;

   // private BigDecimal total; //订单总额

   // private BigDecimal payPrice; //应付的价格

    @Getter @Setter
    private String orderToken;//订单防重令牌

    public Integer getCount(){
        Integer i = 0;
        if(items!=null) {
            for (OrderItemVo item : items) {
                i+= item.getCount();
            }
        }
        return i;
    }

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if(items!=null) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }
    public BigDecimal getPayPrice() {
       return getTotal();
    }
}
